package run;

import java.sql.*;
import database.*;
import eb.User;

import java.io.IOException;
import java.io.PrintWriter;


public class Login {
	
	private Connection conn=null;
	public Login(){}
	private User user;
		
	public boolean checkLogin(String userName,String userpassword){
		try{
			System.out.println(userName);
			System.out.println(userpassword);
			SetConn testconn=new SetConn();
			conn=testconn.setupConn();
			String sql="select * from member where UserName=? and Password=? ";
			ResultSet rs;
			PreparedStatement queryPs=conn.prepareStatement(sql);
			queryPs.setString(1, userName);
			queryPs.setString(2, userpassword);
			rs=queryPs.executeQuery();
			if(rs.next()){
				String name=rs.getString("UserName");
				String password=rs.getString("Password");
				user=new User(rs.getString("UserName"), rs.getString("Password"), rs.getString("RealName"), rs.getString("Tel"), rs.getString("Sex"), rs.getString("Email"));
				if((userName.compareTo(name)==0)&&(userpassword.compareTo(password)==0)){
					return true;
				}
			}
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
		return false;
	}
	public User GetUser(){
		return user;
	}
	
}
